#This file is part of kazami.
#
#    kazami is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    kazami is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with kazami.  If not, see <http://www.gnu.org/licenses/>.

class Board(object):
    
    BLACK = "B"
    BLACKSTART = [[3,4],[4,3]]
    EMPTY = "E"
    NUMCOLS = 8
    NUMROWS = 8
    WHITE = "W"
    WHITESTART = [[3,3],[4,4]]
    
    def __init__(self):
        self.board = [[Board.EMPTY for col in range(0,Board.NUMCOLS)] for row in range(0,Board.NUMROWS)]
        for pos in Board.BLACKSTART:
            self.set(pos[0],pos[1],Board.BLACK)
        for pos in Board.WHITESTART:
            self.set(pos[0], pos[1], Board.WHITE)
    
    def dump(self):
        print(self.board)
    
    def get(self, row, column):
        if row < 0 or column < 0 or row > Board.NUMROWS or column > Board.NUMCOLS:
            return None
        else:
            return self.board[row][column]
    
    def scores(self):
        s = {Board.BLACK : 0, Board.WHITE : 0}
        for row in range(0, Board.NUMROWS):
            s[Board.BLACK] += self.board[row].count(Board.BLACK)
            s[Board.WHITE] += self.board[row].count(Board.WHITE)
        return s
    
    def set(self, row, column, value):
        self.board[row][column] = value
    
